﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.AdvTree;
using DevComponents.Editors;
using PlanningGIS.Win.Controls;
using PlanningGIS.ManageUtility.Modules;
using PlanningGIS.ManageUtility;
using PlanningGIS.Util;
using PlanningGIS.Util.Management;
using PlanningGIS.Util.Regular;
using ESRI.ArcGIS.Geodatabase;
using PlanningGIS.Util.IO;
using System.IO;
using System.Xml.Linq;

namespace PlanningGIS.Manager
{
    /// <summary>
    /// 数据资源
    /// </summary>
    public partial class CtlData : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public CtlData()
        {
            InitializeComponent();
            vnGroup = new List<ValueName>();
            vnGISDB = new List<ValueName>();
            vnAll = new List<ValueName>();
            string[] res = Enum.GetNames(typeof(zjgisResType));
            foreach (string nm in res)
            {
                zjgisResType restype = (zjgisResType)Enum.Parse(typeof(zjgisResType), nm);
                if (restype == zjgisResType.Group || restype == zjgisResType.GISDB) 
                    vnGroup.Add(new ValueName() { Value = nm, Name = restype.GetDescription() });
                else if (restype == zjgisResType.Dataset)
                    vnGISDB.Add(new ValueName() { Value = nm, Name = restype.GetDescription() });
                vnAll.Add(new ValueName() { Value = nm, Name = restype.GetDescription() });
            }

            //List<ValueName> vn = new List<ValueName>();
            //vn.Add(new ValueName() { Value = zjgisResType.Group.ToString(), Name = zjgisResType.Group.GetDescription() });
            //string[] res = Enum.GetNames(typeof(zjgisResType));
            //foreach (string nm in res)
            //{
            //    zjgisResType restype = (zjgisResType)Enum.Parse(typeof(zjgisResType), nm);
            //    if (restype == zjgisResType.Group || restype == zjgisResType.GISDB || restype == zjgisResType.Dataset)    
            //        vn.Add(new ValueName() { Value = nm, Name = restype.GetDescription() });
            //}
            cmbResType.ValueMember = "Value";
            cmbResType.DisplayMember = "Name";
            cmbResType.DataSource = vnGroup;
            resourceTree.ShowCheckBox = false;
        }

        private List<ValueName> vnGroup;
        private List<ValueName> vnGISDB;
        private List<ValueName> vnAll;

        /// <summary>
        /// 当前操作的状态值：1新增；2修改；3删除；4拖动；0未知
        /// </summary>
        private int _OpValue = 0;

        /// <summary>
        /// 是否开始监听值的变化
        /// </summary>
        private bool _Listening = false;

        /// <summary>
        /// 当前值是否有改变
        /// </summary>
        private bool _Changed = false;

        /// <summary>
        /// 
        /// </summary>
        private BillCommands _Commands;
        /// <summary>
        /// Gets or sets the commands associated with the control.
        /// </summary>
        public BillCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    BillCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }

        /// <summary>
        /// Called when Commands property has changed.
        /// </summary>
        /// <param name="oldCmd">Old property value</param>
        /// <param name="newCmd">New property value</param>
        protected virtual void OnCommandsChanged(BillCommands oldCmd, BillCommands newCmd)
        {
            btnCommit.Command = newCmd != null ? newCmd.DataCommands.Save : null;
            btnClose.Command = newCmd != null ? newCmd.DataCommands.Cancel : null;
        }

        /// <summary>
        /// 加载控件，并初始化数据
        /// </summary>
        public void LoadControl()
        {
            _Listening = false;
            ClearText();
            RegValueEvent();
            txtName.Tag = null;
            _OpValue = 0;
            resourceTree.BindData();
            if (resourceTree.Nodes.Count == 0) btnAddGroup_Click(null, null);
        }

        /// <summary>
        /// 监听文本输入框值是否改变
        /// </summary>
        public void RegValueEvent()
        {
            foreach (Control c in this.Controls)
            {
                if (c is TextBoxX)
                {
                    ((TextBoxX)c).TextChanged += Text_TextChanged;
                }
            }
            txtIp.ValueChanged += txtIp_ValueChanged;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void txtIp_ValueChanged(object sender, EventArgs e)
        {
            if (_Listening) _Changed = true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Text_TextChanged(object sender, EventArgs e)
        {
            if (_Listening) _Changed = true;
        }

        /// <summary>
        /// 选择节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void resourceTree_AfterNodeSelect(object sender, DevComponents.AdvTree.AdvTreeNodeEventArgs e)
        {
            cmbResType.DataSource = vnAll;
            if (_Changed)
            {
                DialogResult dlg = MsgHelper.ShowYesOrNoQueryMsgBox("当前值已修改，是否保存？");
                if (dlg == DialogResult.Yes)
                {
                    btnCommit_Click(null, null);
                }
                else
                {
                    _Changed = false;
                }
            }
            if (e.Node == null || e.Node.Tag == null) return;
            _Listening = false;
            ResourceInfo n = (ResourceInfo)e.Node.Tag;
            txtName.Tag = e.Node;
            txtName.Text = n.Name;
            txtIp.Value = n.Server;
            txtUser.Text = n.UserName;
            txtPassword.Text = n.Password;
            txtDb.Text = n.Database;
            txtDb.Tag = n.Database;
            txtDataName.Text = n.DataName;
            txtMinScale.Value = n.MinScale;
            txtMaxScale.Value = n.MaxScale;
            swtbtnScale.Value = n.GetShowScale();
            if (n.MinScale == 0 || n.MaxScale == 0)
            {
                swtbtnScale.Value = false;
            }
            _OpValue = 2;
            zjgisResType type = n.GetResType();
            if (type == zjgisResType.Dataset || type == zjgisResType.FeatureClass || type == zjgisResType.Raster) 
            {
                //cmbResType.Enabled = false;
                cmbResType.DropDownStyle = ComboBoxStyle.DropDown;
                cmbResType.Text = type.GetDescription();
                ChangeStatus(type);
            }
            else
            {
                cmbResType.DropDownStyle = ComboBoxStyle.DropDownList;
                cmbResType.SelectedValue = Enum.Parse(typeof(zjgisResType), n.ResType).ToString();
            }
            _Listening = true;
            SetCtlEnable(false);
        }

        private void SetCtlEnable(bool enabled)
        {
            cmbResType.Enabled = txtIp.Enabled = txtDb.Enabled = txtUser.Enabled = txtPassword.Enabled = txtDataName.Enabled = enabled;
        }


        /// <summary>
        /// 勾选节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void resourceTree_AfterCheck(object sender, AdvTreeCellEventArgs e)
        {
            if (e.Action == eTreeAction.Mouse)
            {
                try
                {
                    if (resourceTree.SelectedNode == null || resourceTree.SelectedNode.Tag == null) return;
                    ((ResourceInfo)resourceTree.SelectedNode.Tag).SetEnable(resourceTree.SelectedNode.Checked);
                    ResourceInfo res = (ResourceInfo)resourceTree.SelectedNode.Tag;
                    int cnt = ManageHelper.DBContext.Update<ResourceInfo>(res, "id", res.ID);
                }
                catch (Exception ex)
                {
                    MsgHelper.ShowErrorMsgbox(ex.ToString());
                }

            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void resourceTree_AfterNodeDrop(object sender, TreeDragDropEventArgs e)
        {
            if (e.Cancel == true) return;
            try
            {
                ResourceInfo res = (ResourceInfo)e.Node.Tag;
                if (e.Node.Parent == null)
                    res.Parent_ID = "";
                else
                    res.Parent_ID = ((ResourceInfo)e.Node.Parent.Tag).ID;
                int cnt = ManageHelper.DBContext.Update<ResourceInfo>(res, "id", res.ID, false);
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.ToString());
            }

        }

        /// <summary>
        /// 选择资源类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbResType_SelectedIndexChanged(object sender, EventArgs e)
        {
            zjgisResType restype = (zjgisResType)Enum.Parse(typeof(zjgisResType), cmbResType.SelectedValue.ToString());
            ChangeStatus(restype);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="restype"></param>
        private void ChangeStatus(zjgisResType restype)
        {
            txtIp.Enabled = txtDb.Enabled = txtUser.Enabled = txtPassword.Enabled = restype == zjgisResType.GISDB;
            //lblDb.Enabled = (restype == zjgisResType.GISDB) ? true : false;
            //txtDb.Enabled = (restype == zjgisResType.GISDB) ? true : false;
            //lblUser.Enabled = restype == zjgisResType.GISDB ? true : false;
            //txtUser.Enabled = restype == zjgisResType.GISDB ? true : false;
            //txtPassword.Enabled = restype == zjgisResType.GISDB ? true : false;
            //lblPassword.Enabled = restype == zjgisResType.GISDB ? true : false;
            //lblIP.Enabled = restype == zjgisResType.GISDB ? true : false;
            //txtIp.Enabled = restype == zjgisResType.GISDB ? true : false;
            //lblResType.Enabled = (restype == zjgisResType.Dataset || restype == zjgisResType.FeatureClass) ? false : true;
            ////cmbResType.Enabled = (restype == zjgisResType.Dataset || restype == zjgisResType.FeatureClass) ? false : true;
            //cmbResType.Enabled = restype != zjgisResType.Dataset;
            ////txtDataName.Enabled = (restype == zjgisResType.Dataset || restype == zjgisResType.FeatureClass || restype == zjgisResType.GISDB) ? false : true;
            //txtDataName.Enabled = restype == zjgisResType.GISDB;
            //lblDataName.Enabled = restype == zjgisResType.GISDB;

            if (restype == zjgisResType.Dataset) lblDataName.Text = "要素集名";
            else if (restype == zjgisResType.FeatureClass) lblDataName.Text = "要素类名";
            else
            {
                lblDataName.Text = "数据名称";
            }
        }

        /// <summary>
        /// 添加组
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddGroup_Click(object sender, EventArgs e)
        {
            _OpValue = 1;
            SetResTypeSource();
            ClearText();
            SetCtlEnable(true);
            //cmbResType.Enabled = true;
            txtName.Tag = null;
            txtIp.Value = OSHelper.GetIP();
            _Listening = true;
        }

        /// <summary>
        /// 添加资源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddRes_Click(object sender, EventArgs e)
        {
            _OpValue = 1;
            SetResTypeSource();
            ClearText();
            txtIp.Value = OSHelper.GetIP();
            ResourceInfo n = (ResourceInfo)resourceTree.SelectedNode.Tag;
            if (n != null)
            {
                zjgisResType type = n.GetResType();
                if (type == zjgisResType.GISDB)
                {
                    cmbResType.Enabled = true;
                    txtIp.Value = n.Server;
                    txtDb.Text = n.Database;
                    txtUser.Text = n.UserName;
                    txtPassword.Text = n.Password;
                }
                else
                {
                    SetCtlEnable(true);
                }
            }
            _Listening = true;
        }

        private void SetResTypeSource()
        {
            if (resourceTree.SelectedNode == null) cmbResType.DataSource = vnGroup;
            else
            {
                ResourceInfo n = (ResourceInfo)resourceTree.SelectedNode.Tag;
                zjgisResType type = n.GetResType();
                if (type == zjgisResType.Group) cmbResType.DataSource = vnGroup;
                else if (type == zjgisResType.GISDB) cmbResType.DataSource = vnGISDB;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void swtbtnScale_ValueChanged(object sender, EventArgs e)
        {
            txtMaxScale.Enabled = swtbtnScale.Value;
            txtMinScale.Enabled = swtbtnScale.Value;
            try
            {
                SetScaleEnableAll(swtbtnScale.Value, resourceTree.SelectedNode);
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.ToString());
            }
        }
        /// <summary>
        /// 设置所有结点比例尺控制启用状态
        /// </summary>
        /// <param name="enable">是否启用</param>
        /// <param name="node">需要设置的节点</param>
        public void SetScaleEnableAll(bool enable, Node node)
        {
            if (node != null)
            {
                ((ResourceInfo)node.Tag).SetEnable(node.Checked);
                ResourceInfo res = (ResourceInfo)node.Tag;
                res.SetShowScale(swtbtnScale.Value);
                int cnt = ManageHelper.DBContext.Update<ResourceInfo>(res, "id", res.ID);
                if (node.HasChildNodes)
                {
                    foreach (Node nd in node.Nodes)
                    {
                        ((ResourceInfo)nd.Tag).SetEnable(nd.Checked);
                        res = (ResourceInfo)nd.Tag;
                        res.SetShowScale(swtbtnScale.Value);
                        cnt = ManageHelper.DBContext.Update<ResourceInfo>(res, "id", res.ID);
                        SetScaleEnableAll(enable, nd);
                    }
                }
            }
        }
        /// <summary>
        /// 清除输入框中的信息
        /// </summary>
        private void ClearText()
        {
            foreach (Control c in this.Controls)
            {
                if (c is TextBoxX)
                {
                    ((TextBoxX)c).Text = "";
                }
            }
            txtIp.Value = "";
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (resourceTree.SelectedNode == null)
            {
                MsgHelper.ShowInfomationMsgbox("请先选择要删除的资源");
                return;
            }
            string msg = "是否确定要删除所选择的资源及其子信息？";
            DialogResult dlg = MsgHelper.ShowYesOrNoQueryMsgBox(msg);
            if (dlg != DialogResult.Yes) return;
            this.Cursor = Cursors.WaitCursor;
            try
            {
                Delete(resourceTree.SelectedNodes);
                for (int i = resourceTree.SelectedNodes.Count - 1; i >= 0; i--)
                {
                    resourceTree.SelectedNodes[i].Remove();
                }
                _Listening = false;
                _Changed = false;
                MsgHelper.ShowInfomationMsgbox("删除成功");
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox("删除失败:" + ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        /// <summary>
        /// 删除资源
        /// </summary>
        /// <param name="nodes"></param>
        private void Delete(NodeCollection nodes)
        {
            foreach (Node nd in nodes)
            {
                if (nd.Nodes.Count > 0)
                {
                    Delete(nd.Nodes);
                }
                if (nd.Tag != null)
                {
                    Dictionary<string, string> tbfields = new Dictionary<string, string>();
                    tbfields.Add("ROLE_REL", "relid");
                    tbfields.Add("RESOURCEINFO", "id");
                    ManageHelper.DBContext.Delete(((ResourceInfo)nd.Tag).ID.Trim(), tbfields);
                }
            }
        }

        /// <summary>
        /// 重新加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReLoad_Click(object sender, EventArgs e)
        {
            if (resourceTree.SelectedNode == null) return;
            bool reLoadAll = true;
            StringBuilder sb = new StringBuilder();
            sb.Append("重新加载资源或仅更新新资源？");
            sb.Append("\n是：全部重新加载。");
            sb.Append("\n否：仅更新或添加新增资源。");
            DialogResult result = MsgHelper.ShowYesNoCancelQueryMsgbox(sb.ToString());
            if (result == DialogResult.No) reLoadAll = false;
            else if (result == DialogResult.Cancel) return;
            this.Cursor = Cursors.WaitCursor;
            try
            {
                ResourceInfo res = (ResourceInfo)resourceTree.SelectedNode.Tag;
                if (res.ResType != ((int)zjgisResType.GISDB).ToString()) return;
                if (resourceTree.SelectedNode.Nodes.Count != 0) 
                {
                    Delete(resourceTree.SelectedNode.Nodes);
                    if (reLoadAll) resourceTree.SelectedNode.Nodes.Clear();
                }
                resourceTree.AddDataset((ResourceInfo)resourceTree.SelectedNode.Tag, resourceTree.SelectedNode, reLoadAll);
                resourceTree.AddRasterResource((ResourceInfo)resourceTree.SelectedNode.Tag, resourceTree.SelectedNode, reLoadAll);
                InsertChild(resourceTree.SelectedNode.Nodes);
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="nodes"></param>
        private void InsertChild(NodeCollection nodes)
        {
            foreach (Node nd in nodes)
            {
                if (nd.Tag == null) continue;
                ResourceInfo res = (ResourceInfo)nd.Tag;
                int cnt = ManageHelper.DBContext.Insert<ResourceInfo>(res);
                if (nd.Nodes.Count > 0)
                {
                    InsertChild(nd.Nodes);
                }
            }
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCommit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MsgHelper.ShowInfomationMsgbox("资源名称不能为空");
                return;
            }
            if (swtbtnScale.Value)
            {
                if (txtMaxScale.Value - txtMinScale.Value >= 0)
                {
                    MsgHelper.ShowInfomationMsgbox("请重新设置显示比例尺！");
                    return;
                }
            }
            else
            {
                txtMinScale.Value = 0;
                txtMaxScale.Value = 0;
            }
            this.Cursor = Cursors.WaitCursor;
            ResourceInfo d = new ResourceInfo()
            {
                Name = txtName.Text.Trim(),
                Server = txtIp.Text.Trim(),
                Database = txtDb.Text.Trim(),
                UserName = txtUser.Text.Trim(),
                Password = txtPassword.Text.Trim(),
                DataName = String.IsNullOrWhiteSpace(txtDataName.Text.Trim()) ? txtUser.Text.Trim() + "." + txtName.Text.Trim() : txtDataName.Text.Trim(),
                MinScale = txtMinScale.Value,
                MaxScale = txtMaxScale.Value,
                ID = Guid.NewGuid().ToString()
            };
            d.SetShowScale(swtbtnScale.Value);
            zjgisResType res = zjgisResType.Group;
            if (!cmbResType.Enabled)
            {
                if (txtName.Tag != null)
                    d.ResType = ((ResourceInfo)(((Node)txtName.Tag).Tag)).ResType;
            }
            else
            {
                res = (zjgisResType)Enum.Parse(typeof(zjgisResType), cmbResType.SelectedValue.ToString());
                d.ResType = ((int)res).ToString();
            }
            d.SetEnable(true);
            try
            {
                int cnt = 0;
                if (_OpValue == 0)
                {
                    _Listening = false;
                    _Changed = false;
                    return;
                }
                else if (_OpValue == 1)
                {
                    if (txtName.Tag == null) d.Parent_ID = "";
                    else d.Parent_ID = ((ResourceInfo)(((Node)txtName.Tag).Tag)).ID;
                    cnt = ManageHelper.DBContext.Insert<ResourceInfo>(d);
                    if (cnt > 0)
                    {
                        if (txtName.Tag != null) resourceTree.AddNode(d, (Node)txtName.Tag);
                        else resourceTree.AddNode(d, null);
                        if (res == zjgisResType.GISDB)
                        {
                            Node[] nds = resourceTree.Nodes.Find(d.ID, true);
                            if (nds != null && nds.Length > 0) InsertChild(nds[0].Nodes);
                        }
                    }
                }
                else if (_OpValue == 2)
                {
                    if (txtName.Tag == null)
                    {
                        MsgHelper.ShowErrorMsgbox("请先选择要修改的资源");
                        return;
                    }
                    string id = ((ResourceInfo)(((Node)txtName.Tag).Tag)).ID;
                    d.ID = id;
                    d.Parent_ID = ((ResourceInfo)(((Node)txtName.Tag).Tag)).Parent_ID;
                    cnt = ManageHelper.DBContext.Update<ResourceInfo>(d, "id", id, false);
                    if (txtName.Tag != null)
                    {
                        ((Node)txtName.Tag).Text = d.Name;
                        ((Node)txtName.Tag).Tag = d;
                    }
                }
                if (cnt < 1)
                {
                    MsgHelper.ShowErrorMsgbox("操作失败:" + ManageHelper.DBContext.Message);
                    return;
                }
                SetScaleAll(resourceTree.SelectedNode);
                _OpValue = 0;
                _Listening = false;
                _Changed = false;
                MsgHelper.ShowInfomationMsgbox("操作成功");
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox("操作失败:" + ex.ToString());
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// 设置所有结点的比例尺范围
        /// </summary>
        /// <param name="enable">是否启用</param>
        /// <param name="node">需要设置的节点</param>
        public void SetScaleAll(Node node)
        {
            if (node != null)
            {
                ((ResourceInfo)node.Tag).SetEnable(node.Checked);
                ResourceInfo resParent = (ResourceInfo)node.Tag;
                if (node.HasChildNodes)
                {
                    foreach (Node nd in node.Nodes)
                    {
                        ((ResourceInfo)nd.Tag).SetEnable(nd.Checked);
                        ResourceInfo res = (ResourceInfo)nd.Tag;
                        res.MaxScale = resParent.MaxScale;
                        res.MinScale = resParent.MinScale;
                        int cnt = ManageHelper.DBContext.Update<ResourceInfo>(res, "id", res.ID);
                        SetScaleAll(nd);
                    }
                }
            }
        }

        /// <summary>
        /// 关闭当前窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, EventArgs e)
        {
            if (_Changed)
            {
                DialogResult dlg = MsgHelper.ShowYesOrNoQueryMsgBox("资源列表已变更，是否保存");
                if (dlg == DialogResult.Yes)
                {
                    btnCommit_Click(null, null);
                }
            }
            _Changed = false;
            _Listening = false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnToXml_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        private void SaveToXml(string filename)
        {

            XDeclaration dec = new XDeclaration("1.0", "utf-8", "yes");
            XDocument xml = new XDocument(dec);
            XElement root = new XElement("Resources");
            foreach (Node node in resourceTree.Nodes)
            {
                XElement e = CreateElements(node);
                root.Add(e);
            }
            xml.Add(root);
            xml.Save(filename);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private XElement CreateElements(Node node)
        {
            XElement root = CreateElement(node);
            foreach (Node n in node.Nodes)
            {
                XElement e = CreateElements(n);
                root.Add(e);
            }
            return root;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private XElement CreateElement(Node node)
        {
            return new XElement("ResourceInfo",
                new XAttribute("Name", node.Name),
                new XAttribute("Text", node.Text)
                );
        }

        private void resourceTree_BeforeNodeDrop(object sender, TreeDragDropEventArgs e)
        {
            DialogResult dlg = MsgHelper.ShowYesOrNoQueryMsgBox("是否修改资源节点层级？");
            if (dlg != DialogResult.Yes)
            {
                e.Cancel = true;
            }
        }
    }
}
